package com.quanyan.assets.service.impl;

import com.quanyan.api.APIResponse;
import com.quanyan.assets.emun.AssetsErrorEnum;
import com.quanyan.assets.entity.TbCurrency;
import com.quanyan.assets.entity.TbCurrencyExample;
import com.quanyan.assets.mapper.TbCurrencyMapper;
import com.quanyan.assets.service.UtilCurrencyService;
import com.quanyan.common.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by wmb on 2016/6/29.
 */
@Service("utilCurrencyService")
public class UtilCurrencyServiceImpl implements UtilCurrencyService {
    @Autowired
    private TbCurrencyMapper tbCurrencyMapper;
    @Override
    public BigDecimal exchangeAssetsAmount(byte assetsId) {
        TbCurrencyExample tbCurrencyExample=new TbCurrencyExample();
        tbCurrencyExample.createCriteria().andAssetsIdEqualTo(assetsId);
        List<TbCurrency> currencyList=tbCurrencyMapper.selectByExample(tbCurrencyExample);
        if(currencyList.isEmpty()){
            throw new BizException(AssetsErrorEnum.CURRENCY_RECORD_DO_NOT_EXISTS);
        }
        //获取兑换比例
        return new BigDecimal(currencyList.get(0).getRmbAmount());
    }
}
